package com.zsc.wxm.ysh.anjo.security;

import com.zsc.wxm.ysh.anjo.utils.Md5Util;
import org.springframework.security.crypto.password.PasswordEncoder;
import org.springframework.stereotype.Component;

/**
 * 描述： 密码匹对
 *
 * @author playmaker
 * @since 2021/2/6 15:02
 */
@Component
public class DefaultPasswordEncoder implements PasswordEncoder {

    public DefaultPasswordEncoder() {
        this(-1);
    }

    public DefaultPasswordEncoder(int strength) {

    }

    /**
     * 进行Md5加密
     *
     * @param charSequence 明文密码
     * @return 加密后的密码
     */
    @Override
    public String encode(CharSequence charSequence) {
        return Md5Util.md5(charSequence.toString());
    }

    /**
     * 密码匹配
     *
     * @param charSequence    明文
     * @param encodedPassword 加密后的密码
     * @return boolean
     */
    @Override
    public boolean matches(CharSequence charSequence, String encodedPassword) {
        return encodedPassword.equals(Md5Util.md5(charSequence.toString()));
    }
}
